package com.keboom.show.service.impl;

import com.keboom.show.mapper.SpUserMapper;
import com.keboom.show.model.SpUser;
import com.keboom.show.model.SpUserExample;
import com.keboom.show.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by keboom on 2020/9/6.
 */
@Service
public class UsersServiceImpl implements UsersService {
    @Autowired
    private SpUserMapper userMapper;

    @Override
    public SpUser findByUserId(Integer id) {
        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public SpUser findByUsername(String name) {
        SpUserExample example = new SpUserExample();
        example.createCriteria().andUsernameEqualTo(name);
        List<SpUser> spUsers = userMapper.selectByExample(example);
        if (spUsers != null && spUsers.size() > 0){
            SpUser spUser = spUsers.get(0);
            return spUser;
        }
        return null;
    }
}
